package www.cskaoyan.com.service.impl;

import www.cskaoyan.com.bean.Account;
import www.cskaoyan.com.bean.ClassManager;
import www.cskaoyan.com.bean.Group;
import www.cskaoyan.com.dao.ClassManagerDao;
import www.cskaoyan.com.dao.GroupManagerDao;
import www.cskaoyan.com.dao.LoginDao;
import www.cskaoyan.com.service.ClassManagerService;
import www.cskaoyan.com.service.LoginService;
import www.cskaoyan.com.utils.Response;

import java.sql.SQLException;
import java.util.List;

public class ClassManagerServiceImpl implements ClassManagerService {

    // 调用持久层
    ClassManagerDao classManagerDao;
    GroupManagerDao groupManagerDao;

    public ClassManagerServiceImpl(){
        this.classManagerDao = new ClassManagerDao();
        this.groupManagerDao = new GroupManagerDao();
    }
    @Override
    public void create(ClassManager classManager)throws SQLException {
         classManagerDao.create(classManager.getClassName(), classManager.getBeginDate());

    }

    // 获取所有班级列表
    @Override
    public List<ClassManager> getClassList() throws SQLException {

        List<ClassManager> list = classManagerDao.getClassList();

        return list;
    }

    // 根据id删除班级信息
    @Override
    public Response deleteClass(ClassManager classManager) throws SQLException {
        int classId = classManager.getId();
        // 要先确定这个班级id下有没有分组了, 没有分组, 有分组不能删除
        List<Group> list = groupManagerDao.selectGroupListByClassID(classId);
        if (list.size() > 0){
            return  new Response(10, "请先删除该班级下的分组", false);
        }
        // TODO: 后续还需要判断这个班级下有没有同学了

        classManagerDao.deleteClass(classId);

        return new Response(200, "删除成功", true);
    }
}
